package com.supermap.gwfs.datashare.util;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**  
 * @Description: TODO
 * @author zhoujian
 * @date 2017-8-29
 * @version V1.0 
 */
public class CollectionUtil
{
	/**
     * 求Map<K,V>中Key(键)的最小值
     * @param map
     * @return
     */
    public static Object getMinKey(Map<Integer, Integer> map) {
        if (map == null) return null;
        Set<Integer> set = map.keySet();
        Object[] obj = set.toArray();
        Arrays.sort(obj);
        return obj[0];
    }
 
    /**
     * 求Map<K,V>中Value(值)的最小值
     * @param map
     * @return
     */
    public static Object getMinValue(Map<Integer, Integer> map) {
        if (map == null) return null;
        Collection<Integer> c = map.values();
        Object[] obj = c.toArray();
        Arrays.sort(obj);
        return obj[0];
    }
    
    public static Object getMinkeyByMinValue(Map<Integer, Integer> map)
	{
    	if (map == null) return null;
    	int minPriority = 999;
    	int minCode = 999;
    	for (Integer code : map.keySet())
		{
			if (map.get(code) <= minPriority)
			{
				minPriority = map.get(code);
				minCode = code;
			}
		}
    	
		return minCode;
	}
    
    
    public static boolean ArrayContain(String[] arr, String targetValue) {
        return Arrays.asList(arr).contains(targetValue);
    }
    
    
    public static void main(String[] args)
	{
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		map.put(999, 87);
		map.put(888, 80);
		
		map.put(777, 100);
		map.put(555, 45);
		map.put(666, 60);
		map.put(1001, 10);
		Object i = CollectionUtil.getMinkeyByMinValue(map);
		System.out.println(i.toString());
	}
}
